<?php 
/**
 * 双维度双柱状图
 *
 * PHP version 5
 *
 * @package   Ecga
 * @author    Farmer.Li <none@none.com>
 * @copyright 2010 Xingchangxinda Inc.
 * @version   SVN: $Id$
 */
namespace Project\Apps\Ecga\Library\FusionCharts;

use \Project\Apps\Ecga\Library\FusionCharts\ChartXml;
use \Exception;

/**
 * 双维度双柱状图
 *
 * PHP version 5
 *
 * @package   Ecga
 * @author    Farmer.Li <none@none.com>
 * @copyright 2010 Xingchangxinda Inc.
 * @version   Release: <0.2>
 */
class MSCombiDY2D extends ChartXml
{
    /**
     * 构造
     *
     * @param string $caption 标题
     */
    public function __construct($caption)
    {
        parent::__construct($caption);
        $this->setStyle(
            array(
                'showValues' => 0,
                'setAdaptiveYMin' => '1',
                'setAdaptiveSYMin' => '1',
    			'sFormatNumber' => 1,
    			'sFormatNumberScale' => 0,
    			'sDecimalPrecision' => 2
            )
        );
    }
    
    /**
     * 设置数据
     *
     * @param string $leftYName  左Y轴名称
     * @param array  $leftYData  左Y轴数据
     * @param string $rightYName 右Y轴名称
     * @param array  $rightYData 右Y轴数据
     * 
     * @return void
     */
    public function setData($leftYName, $leftYData, $rightYName, $rightYData)
    {
        $categories = array(
			'tagName' => 'categories',
			'__child' => array()
		);
		foreach ($leftYData as $key => $value) {
			$categories['__child'][] = array(
				'tagName' => 'category',
				'__attr' => array(
					'label' => $key
				)
			);
		}
		$this->data['__child']['categories'] = $categories;
		$this->_setData($leftYName, $leftYData, array('parentYAxis' => "P"));
		$this->_setData($rightYName, $rightYData, array('parentYAxis' => "S", 'renderAs' => "Column"));
    }
    
    /**
     * 设置数据
     *
     * @param string $name      名称
     * @param array  $data      数据
     * @param array  $attribute 属性
     * 
     * @return void
     */
    private function _setData($name, $data, $attribute = array())
    {
        $result = array(
			'tagName' => 'dataset',
			'__child' => array()
		);
		$result['__attr']['seriesname'] = $name;
		foreach ($attribute as $key => $value) {
		    $result['__attr'][$key] = $value;
		}
		foreach ($data as $key => $value) {
		    $result['__child'][] = array(
                'tagName' => 'set',
                '__attr' => array(
                    'value' => $value
                )
		    );
		}
		$this->data['__child'][] = $result;
    }
}
?>